package com.lobo.blog.service.impl;

import com.lobo.blog.entity.User;
import com.lobo.blog.exception.UserNotFoundException;
import com.lobo.blog.mappers.AdminUserMapper;
import com.lobo.blog.service.AdminUserLoginService;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import javax.annotation.Resource;

/**
 * @authoer:MacieSerenity
 * @createDate: 2022/9/28
 * @description:
 */
@Service
public class AdminUserLoginServiceImpl implements AdminUserLoginService {

    @Resource
    private AdminUserMapper adminUserMapper;

    @Override
    public User findUserInfoByUsername(String name) {
        User user = adminUserMapper.getUserInfoByUsername(name);
        return user;
    }

    @Override
    public User findUser(String username, String password) {
        //手动加盐
        password += "salt";
        //将密码进行MD5加密
        password = DigestUtils.md5DigestAsHex(password.getBytes());
        User user = adminUserMapper.findUser(username, password);
        if (user == null) {
            throw new UserNotFoundException();
        }
        return user;
    }
}
